package com.daify.threadlearn.chapter01.order04;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author daify
 * @date 2019-06-05
 */
public class Delegaring {

    private final ConcurrentMap<String,Point> locations;

    private final Map<String,Point> unmodifiable;

    public Delegaring(Map<String,Point> points) {
        this.locations = new ConcurrentHashMap<String, Point>(points);
        this.unmodifiable = Collections.unmodifiableMap(locations);
    }


    public Map<String, Point> getLocations() {
        return unmodifiable;
    }

    public Point getLocation(String id) {
        return locations.get(id);
    }

    public void setLocations (String id,int x,int y) {
        if (locations.replace(id,new Point(x,y)) == null){
            throw new RuntimeException();
        }
    }
}
